// wygzgyw
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
template <typename T> void write(T t) {
	if (t<0) { putchar('-'); write(-t); return; }
	if (t>9) write(t/10);
	putchar('0'+t%10);
}
template <typename T> void writeln(T t) { write(t); puts(""); }
#define MP make_pair
typedef long long ll;
const int mod=(1e9)+7;
const int maxn=(8e5)+10;
int T,n;
int fa[maxn];
int sz[maxn],s[maxn];
ll all;
ll ans[maxn],C2[maxn];
int head[maxn],tot,nxt[maxn*2],to[maxn*2],w[maxn*2];
void update(int &x,int y) { x+=y; if (x>=mod) x-=mod; }
int now,f[maxn];
int q[maxn],tl,W[maxn];
void dfs(int u,int p) {
	q[++tl]=u; f[u]=p;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i];
		if (v==p) continue;
		dfs(v,u); W[v]=w[i];
	}
}
void add(int x,int y,int z) { tot++; nxt[tot]=head[x]; head[x]=tot; to[tot]=y; w[tot]=z; }
pair<int,int> E[maxn];
int main() {
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	read(n); for (int i=1;i<=n;i++) head[i]=0; tot=0;
	for (int i=1;i<=n;i++) C2[i]=(ll)i*(i-1)/2;
	for (int i=1;i<n;i++) {
		int x,y,z; read(x),read(y),read(z);
		E[i]=MP(x,y);
		add(x,y,z),add(y,x,z);
	}
	tl=0; dfs(1,0);
	for (int i=1;i<=n;i++) ans[i]=0;
	for (int i=1;i<=20;i++) {
		now=i;
		for (int j=1;j<=n;j++) sz[j]=0,s[j]=1;
		fa[1]=1; sz[1]=1;
		for (int j=2;j<=n;j++) {
			int v=q[j],u=f[v];
			if (W[v]>=i) fa[v]=fa[u]; else fa[v]=v;
			sz[fa[v]]++;
		}
		
		for (int j=n;j>=2;j--) {
			int v=q[j],u=f[v];
			if (W[v]>=i) s[u]+=s[v];
		}
		
		all=0; for (int j=1;j<=n;j++) if (fa[j]==j) all+=C2[sz[j]];
		
		for (int j=2;j<=n;j++) {
			int v=j,u=f[j];
			if (fa[u]==fa[v]) {
				ans[v]+=all-C2[sz[fa[u]]]+C2[sz[fa[u]]-s[v]]+C2[s[v]];
			}
			else ans[v]+=all;
		}
	}
	
	for (int i=1;i<n;i++) {
		int x=E[i].first,y=E[i].second;
		if (f[x]==y) swap(x,y);
		printf("%lld\n",ans[y]);
	}
	
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Integer overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/
